import Vue from "vue";
import App from "./App.vue";
import router from "./router"
import store from "./store";
import "./plugins/element.js";

Vue.config.productionTip = false;

//引入reset.css
import '@/assets/css/reset.css'
//引入iconfont图标css文件
import '@/assets/icons/iconfont.css'

//路由守卫
router.beforeEach((to,from,next) => {
  console.log('to:', to)
  //第一步：是否需要鉴权
  let flag = to.matched.some(item => item.meta.auth)
  if (flag) {
    //第二步：获取token
    const token = sessionStorage.getItem('token');
    if (!token) {
      return next({
        //要跳转的路由
        path: '/login',
        //通过query携带要传递的参数,query是一个对象
        query: {
          redirect:to.fullPath
        }
     })
    }
    //有token,就直接放行
    next()

  } else {
    next()
  }

  
  
})

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
